package health.lm.com.shop.presenter;

import android.text.TextUtils;

import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.vondear.rxtool.RxTool;

import java.util.ArrayList;
import java.util.List;

import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.component_base.util.JsonUtil;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.shop.activity.HLCompanyLeaderActivity;
import health.lm.com.shop.entity.HLCompanyLeaderEntity;
import health.lm.com.shop.entity.HLCompanyLeaderResponse;
import health.lm.com.shop.entity.HLCompanyLeaderSectionEntity;
import health.lm.com.shop.model.MallModel;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.presenter
 * Date：2019/8/14 8:31
 * Introduce：商会领导
 */
public class HLCompanyLeaderPresenter extends XPresent<HLCompanyLeaderActivity> {
    public void getData(String id) {
        if (TextUtils.isEmpty(id)) return;
        MallModel.getInstance().getLeaderData(id, new SimpleCallBack<HLCompanyLeaderResponse>() {
            @Override
            public void onSuccess(HLCompanyLeaderResponse pHLCompanyLeaderResponse) {
                if (hasV()) getV().setNewData(getResource(pHLCompanyLeaderResponse.getLader_list()));
            }
        });
    }

    private List<HLCompanyLeaderSectionEntity> getResource(List<HLCompanyLeaderEntity> leaderEntity) {
        //String json = JsonUtil.getJson(RxTool.getContext(), "hl_companyy_leader.json");
        //List<HLCompanyLeaderEntity> leaderEntity = new GsonBuilder().create().fromJson(json, new TypeToken<List<HLCompanyLeaderEntity>>() {
        //}.getType());
        List<HLCompanyLeaderSectionEntity> list = new ArrayList<>();
        for (HLCompanyLeaderEntity entity : leaderEntity) {
            HLCompanyLeaderSectionEntity sectionEntity = new HLCompanyLeaderSectionEntity(true, entity.getTag());
            list.add(sectionEntity);
            for (HLCompanyLeaderEntity.DataEntity dataEntity : entity.getData()) {
                HLCompanyLeaderSectionEntity sectionEntity2 = new HLCompanyLeaderSectionEntity(dataEntity);
                sectionEntity2.t.setTag(entity.getTag());
                list.add(sectionEntity2);
            }
        }
        return list;
    }
}
